home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Technology Seed / August 1998 ADC Seed CD.toast / Language Analysis Manager / DarumaDR1Package / Examples / DictionaryAccess / Sources / Utilities.c < prev   
Encoding:
C/C++ Source or Header  |  1998-03-27  |  5.3 KB  |  191 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Utilities.c
  3.     
  4.     Contains:    A Sample application for dictionary access.
  5.  
  6.      Version:    Technology:    System 8
  7.                  Release:    Daruma Developer Release 1
  8.  
  9.      Copyright:    1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Contact:    daruma@apple.com
  12.  
  13. */
  14.  
  15.  
  16. #include "DictionaryAccess.h"
  17. #include "FunctionProto.h"
  18.  
  19. #include <Windows.h>
  20. #include <TextUtils.h>
  21. #include <string.h>
  22. #include <Memory.h>
  23. #include <Appearance.h>
  24. #include <Lists.h>
  25. #include <OSUtils.h>
  26.  
  27.  
  28. //========================================================================================
  29. //    GetDialogEditTextItemString
  30. //========================================================================================
  31. void GetDialogEditTextItemString( DialogPtr dialog, SInt16 item, Str255 string)
  32. {
  33.     OSStatus        err;
  34.     Size            actualSize;
  35.     ControlHandle    controlHandle;
  36.  
  37.     err = GetDialogItemAsControl( dialog, item, &controlHandle);
  38.     
  39.     if ( err == noErr )
  40.     {
  41.         GetControlData( controlHandle, (ControlPartCode)0, kControlEditTextTextTag, 255, (Ptr)&string[1], &actualSize);
  42.         string[0] = actualSize;
  43.     }
  44. }
  45.  
  46.  
  47. //========================================================================================
  48. //    SetDialogEditTextItemString
  49. //========================================================================================
  50. void SetDialogEditTextItemString( DialogPtr dialog, SInt16 item, ConstStr255Param string)
  51. {
  52.     OSStatus        err;
  53.     ControlHandle    controlHandle;
  54.  
  55.     err = GetDialogItemAsControl( dialog, item, &controlHandle);
  56.     
  57.     if ( err == noErr )
  58.     {
  59.         SetControlData( controlHandle, (ControlPartCode)0, kControlEditTextTextTag, string[0], (Ptr)&string[1]);
  60.         DrawOneControl( controlHandle);
  61.     }
  62. }
  63.  
  64.  
  65. //========================================================================================
  66. //    GetDialogStaticTextItemString
  67. //========================================================================================
  68. void GetDialogStaticTextItemString( DialogPtr dialog, SInt16 item, Str255 string)
  69. {
  70.     OSStatus        err;
  71.     Size            actualSize;
  72.     ControlHandle    controlHandle;
  73.  
  74.     err = GetDialogItemAsControl( dialog, item, &controlHandle);
  75.     
  76.     if ( err == noErr )
  77.     {
  78.         GetControlData( controlHandle, (ControlPartCode)0, kControlStaticTextTextTag, 255, (Ptr)&string[1], &actualSize);
  79.         string[0] = actualSize;
  80.     }
  81. }
  82.  
  83.  
  84. //========================================================================================
  85. //    SetDialogStaticTextItemString
  86. //========================================================================================
  87. void SetDialogStaticTextItemString( DialogPtr dialog, SInt16 item, ConstStr255Param string)
  88. {
  89.     OSStatus        err;
  90.     ControlHandle    controlHandle;
  91.  
  92.     err = GetDialogItemAsControl( dialog, item, &controlHandle);
  93.     
  94.     if ( err == noErr )
  95.     {
  96.         SetControlData( controlHandle, (ControlPartCode)0, kControlStaticTextTextTag, string[0], (Ptr)&string[1]);
  97.         DrawOneControl( controlHandle);
  98.     }
  99. }
  100.  
  101.  
  102. //========================================================================================
  103. //    SelectDialogEditTextItemString
  104. //========================================================================================
  105. void SelectDialogEditTextItemString( DialogPtr dialog, SInt16 item, SInt16 start, SInt16 end)
  106. {
  107.     OSStatus                        err;
  108.     ControlHandle                    controlHandle;
  109.     ControlEditTextSelectionRec        selection;
  110.  
  111.     err = GetDialogItemAsControl( dialog, item, &controlHandle);
  112.     
  113.     if ( err == noErr )
  114.     {
  115.         selection.selStart = start;
  116.         selection.selEnd = end;
  117.         
  118.         SetControlData( controlHandle, (ControlPartCode)0, kControlEditTextSelectionTag, sizeof( selection), (Ptr)&selection);
  119.         DrawOneControl( controlHandle);
  120.     }
  121. }
  122.  
  123.  
  124. //========================================================================================
  125. //    HiliteButtonDialogItem
  126. //========================================================================================
  127. void HiliteButtonDialogItem( DialogPtr dialog, SInt16 item)
  128. {
  129.     OSStatus                        err;
  130.     ControlHandle                    controlHandle;
  131.  
  132.     err = GetDialogItemAsControl( dialog, item, &controlHandle);
  133.     
  134.     if ( err == noErr && IsControlActive( controlHandle) )
  135.     {
  136.         UInt32    finalTicks;
  137.  
  138.         HiliteControl( controlHandle, kControlButtonPart);
  139.         Delay( 10, &finalTicks);
  140.         HiliteControl( controlHandle, 0);
  141.     }
  142. }
  143.  
  144.  
  145. // ========================================================================================
  146. // GetListHandleFromControl
  147. // ========================================================================================
  148. ListHandle GetListHandleFromControl( ControlHandle controlHandle )
  149. {
  150.     OSStatus    err;
  151.     ListHandle    listHandle;
  152.     Size        actualSize;
  153.  
  154.     err = GetControlData( controlHandle, (ControlPartCode)0, kControlListBoxListHandleTag, sizeof(listHandle), (Ptr)&listHandle, &actualSize);
  155.     if ( err != noErr ) listHandle = NULL;
  156.         
  157.     return listHandle;
  158. }
  159.  
  160.  
  161. // ========================================================================================
  162. // PascalStrToCStr
  163. // ========================================================================================
  164. char *PascalStrToCStr ( StringPtr pStr )
  165. {
  166.     long    len = (long)pStr[0];
  167.     
  168.     BlockMoveData( &pStr[1], &pStr[0], len);
  169.     pStr[len] = '\0';
  170.     
  171.     return (char *)&pStr[0];
  172. }
  173.  
  174.  
  175. // ========================================================================================
  176. // CStrToPascalStr
  177. // ========================================================================================
  178. StringPtr CStrToPascalStr ( char *cStr )
  179. {
  180.     long    len = strlen( cStr);
  181.     
  182.     BlockMoveData( &cStr[0], &cStr[1], len);
  183.     cStr[0] = len;
  184.     
  185.     return (StringPtr)&cStr[0];
  186. }
  187.  
  188.  
  189.  
  190.  
  191.